package com.easysoft.framework.warning.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.warning.mapper.SysWarningTipsMapperExtd;
import com.easysoft.framework.warning.model.SysWarningTips;
import com.easysoft.framework.warning.model.SysWarningTipsQuery;
import com.easysoft.framework.warning.model.SysWarningTipsView;
import com.easysoft.framework.workflow.model.SysWorkflow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("service.SysWarningTipsService")
public class SysWarningTipsService {

    @Autowired
    @Qualifier("mapper.SysWarningTipsMapperExtd")
    private SysWarningTipsMapperExtd sysWarningTipsMapperExtd;

    @DataSource(DataSource.SLAVE)
    public List<SysWarningTipsView> selectSysWarningTipsByPage(Page page, SysWarningTipsQuery query) {
        int maxRow = sysWarningTipsMapperExtd.selectCountAllWarningTips(query);
        if (maxRow == 0){
            return new ArrayList<SysWarningTipsView>();
        }
        page.setMaxRow(maxRow);
        return sysWarningTipsMapperExtd.selectSysWarningTipsByPage(page,query);
    }

    @DataSource(DataSource.MASTER)
    public int addSysWarningTips(SysWarningTips sysWarningTips) {
        sysWarningTips.setId(UUIDUtils.getUUID());
        sysWarningTips.setCreateTime(new Date());
        return sysWarningTipsMapperExtd.insertSelective(sysWarningTips);
    }

    @DataSource(DataSource.SLAVE)
    public SysWarningTips selectSysWarningTipsById(String id) {
        return sysWarningTipsMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysWarningTips(SysWarningTips sysWarningTips){
        return sysWarningTipsMapperExtd.updateByPrimaryKeySelective(sysWarningTips);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysWarningTips(String id) {

        return sysWarningTipsMapperExtd.deleteByPrimaryKey(id);
    }

}
